package com.year_23.april;

import java.util.HashMap;

/**
 * 1 两数之和
 * @Author jsh
 * @Date 2023/4/19 22:30
 * @Version 1.0
 */
public class Day19_2 {
    public static void main(String[] args) {
        int[] arr = {2,7,11,11,11};

        for (int i : twoSum(arr, 22)) {

            System.out.println(i);

        }
    }
    public static  int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            int other = target - nums[i];
            if (map.containsKey(other))
                return new int[]{i, map.get(other)};
            map.put(nums[i], i);
        }

        return new int[2];
    }
}
